home *** CD-ROM | disk | FTP | other *** search
/ F1 Licenseware / F1 Licenseware - Volume 1.iso / disks / 050a.dms / 050a.adf / TEXTS / chapter03.txt < prev    next >
Text File  |  1992-02-26  |  4KB  |  121 lines

  1.                      The Absolute Beginners Guide To Amos
  2.                     -------------------------------------
  3.                                 Chapter Three
  4.                                 -------------
  5. In this chapter we will be covering variables. Before you start telling 
  6. yourself you`ll never understand variables. Let me tell you it`s not half as
  7. complicated as it first sounds. 
  8.  
  9. A variable is a letter or combination of letters and numbers that hold a 
  10. numerical value.
  11.  
  12. Read the last paragraph again slowly and try to understand it.  
  13.  
  14. Here are some examples of a variable name:
  15.  
  16. A
  17.  
  18. AA
  19.  
  20. ABC
  21.  
  22. AVARIABLE
  23.  
  24. YETANOTHER
  25.  
  26. F1
  27.  
  28. F1LW4
  29.  
  30. I will explain what use variables are to us in a moment so don`t worry
  31. why we use them for now just try and understand how they work.
  32.  
  33. To use a variable we first have to give it a name. 
  34. This can be almost anything as long as it starts with a letter and not a 
  35. number and does not contain spaces. If you want a space you can use the 
  36. underscore character _ like so:
  37.  
  38. FRED_FLINTSTONE_RULES
  39.  
  40. Another restriction is that you must not use keywords, PRINT for example is a
  41. keyword.  You can use a key word amongst other letters and numbers though for
  42. example XPRINT5. But don't worry about keywords too much for now.
  43.  
  44. Let`s set up a variable of our own. We will call our variable F1.
  45. We must now tell Amos what value we want F1 to hold initially. 
  46. This is quite straight forward, we use the = sign and then the value so let 
  47. us say we want F1 to hold the value of 10:
  48.  
  49. F1=10
  50.  
  51. It`s as straight forward as that.  We can now change the value of F1 very 
  52. easily from within our program using the INC and DEC commands.
  53.  
  54. INC F1
  55.  
  56. This will add 1 to the current value of F1.  Let`s imagine that we have a
  57. program that counts cars that pass a motorway junction and each time a
  58. car passes we INCrement our counter by 1.  Our variable (or counter if you
  59. like) is F1 and to start off we want F1 to equal 0 as we haven`t started 
  60. counting yet. Right, we have sat down at our imaginary computer and the first
  61. car has passed so we have to add 1 to F1 we do this in Amos with INC, as 
  62. described earlier:
  63.  
  64. INC F1
  65.  
  66. F1 now equals 1. Let`s say we now decide to go for lunch and someone else
  67. takes over our imaginary computer and they would like to know out of 
  68. interest how many cars you have counted. In Amos we would do this:
  69.  
  70. PRINT F1
  71.  
  72. Which will PRINT the current value of F1 on the screen, the person would see
  73. that F1 equalled 1 and call you a lazy toe rag.  
  74. We will cover the printing of a variable in the next chapter.
  75.  
  76. DEC is the exact opposite to INC this will subtract 1 from F1 like this,
  77.  
  78. F1=1
  79. DEC F1
  80. PRINT F1
  81.  
  82. Do you know what the answer would be? That is right, 0.
  83. If F1 equalled 0 and you DECremented it F1 would equal -1 (minus one).
  84.  
  85. Now if you have understood this chapter so far you may be thinking what if
  86. I wanted to DECrement more than one off of F1 or INC more than one?
  87. Well you could of course do this,
  88.  
  89. F1=10
  90. DEC F1
  91. DEC F1
  92. DEC F1
  93. DEC F1
  94.  
  95. This would leave F1 equalling 6, not very pretty and it`s time consuming 
  96. isn`t it?  How about this:
  97.  
  98. F1=10   : REM Make our variable (or counter if you like) equal 10
  99. F1=F1-4 : REM Make our counter equal our counter-4, F1 now equals 6
  100.           REM F1=10-4
  101. or 
  102.  
  103. F1=10
  104. F1=F1+4 : REM F1 now equals 14
  105.  
  106. which is a lot shorter, neater and easier to understand. There is another
  107. way using ADD var,number and ADD var,-number commands but you have enough to
  108. cope with at the moment. 
  109.  
  110. Getting back to WHY we would want a number to be represented by a letter!
  111. The reason is it`s basically the only way to manipulate numbers. You wont
  112. find many programs written in ANY language that do not use variables.
  113. Check out chapter 4 in your Amos manual for more info on variables.
  114.  
  115. Now load EXAMPLE3.Amos and experiment with the INC and DEC commands.
  116. I know the program itself is not exciting but I am trying to keep things
  117. clear and simple. Things will hot up soon enough.
  118.  
  119.                             End of chapter three
  120.                             ^^^^^^^^^^^^^^^^^^^^
  121.